// pages/good/search.js
const api = require("../../request/api")
const request = require("../../request/request")
const util = require("../../utils/util")
const App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keyword_value: '',
    uid: 9,
    page: 1,
    page_size: 15,
    search_list: [],
    hot_search_list: [{
      text: '加味逍遥丸'
    },{
      text: '千金片'
    },{
      text: '千金胶囊'
    },{
      text: '止带丸'
    },{
      text: '润手'
    },{
      text: '妇科千金片'
    },{
      text: '疏肝清热'
    },{
      text: '头晕目眩'
    },{
      text: '月经不调'
    }]
  },
  hot_search_input_hot: [],
  hot_search_input_normal: [],

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      uid: util.getAppValue(App.globalData.uid)
    })
    this.get_hot_search_input()
  },
  keyword_input(e) {
    this.setData({
      keyword_value: e.detail.value
    })
  },
  inputChange: function (e) {
    this.setData({
      inputValue: e.detail.value
    })
  },
  searching_good() {
    console.log(this.data.keyword_value)
    let params = {
      name: this.data.keyword_value,
      page: this.data.page,
      pageSize: this.data.page_size,
      uid: this.data.uid 
    }
    util.showLoading('加载中')
    request.post(api.goods_search, params).then(res=>{
      util.hideLoading()
      this.setData({
        search_list: res
      })
    })
  },
  go_detail(e) {
    let id = e.detail.currentTarget.dataset.id
    if (!id) {
      id = 10
    }
    wx.navigateTo({
      url: '/pages/good/detail?id=' + id,
    })
  },
  get_hot_search_input() {
    this.setData({
      hot_search_input_hot: this.data.hot_search_list.slice(0,3),
      hot_search_input_normal: this.data.hot_search_list.slice(3)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})